package edge;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;

/**
 * Created by Administrator on 2016/11/16.
 */
@SpringBootApplication
@EnableEurekaClient
@EnableZuulProxy
@EnableResourceServer
@EnableHystrix
//@EnableAuthorizationServer  使用第二个configuration需要加上的注解，启动oauth2服务端
public class EdgeApplication {

    public static void main(String[] args) {
        SpringApplication.run(EdgeApplication.class, args);
    }

    @Configuration
    public static class RestSecurityConfig  extends WebSecurityConfigurerAdapter{
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.csrf().disable();
        }
    }

  /*  要想跑通整个流程，我们必须分配 client_id , client_secret 才行。
    Spring Security OAuth2的配置方法是编写 @Configuration 类继承
    AuthorizationServerConfigurerAdapter ，
    然后重写 void configure(ClientDetailsServiceConfigurer clients) 方法，如：*/

  /*  @Configuration
    public static class AuthConfig extends AuthorizationServerConfigurerAdapter{
        @Override
        public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
            clients.inMemory()  //使用inMemory存储
                    .withClient("client_id") //client_id
                    .secret("client_secret")//client_secret
                    .authorizedGrantTypes("authorization_code")//该client容许的授权类型
                    .scopes("app"); //容许授权的范围
        }
    }*/

   /* 访问授权页面：
    localhost:8080/oauth/authorize?client_id=client&response_type=code&redirect_uri=http: // www.baidu.com
    此时浏览器会让你输入用户名密码，这是因为 Spring Security 在默认情况下会对所有URL添加Basic Auth认证。默认的用户名为 user
    , 密码是随机生成的，在控制台日志中可以看到。*/



}

